package Controller;

import POJO.Berth;
import POJO.Department;
import POJO.InputPOJO.BerthBindInput;
import POJO.InputPOJO.BerthInput;
import POJO.Model.PageResponseModel;
import POJO.Model.Pagination;
import POJO.Model.ResponseModel;
import POJO.Vo.BerthVo;
import Service.BerthService;
import Service.DepartmentService;
import javafx.scene.shape.VLineTo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller("BerthController")
public class BerthController {

    @Resource
    BerthService berthService;
    @Resource
    ResponseModel responseModel;
    @Resource
    DepartmentService departmentService;
    @Resource
    PageResponseModel pageResponseModel;


    /*   病床新增*/
    /*会判断输入的berth是否已经存在*/
    @RequestMapping(value = "/berth/new")
    public @ResponseBody ResponseModel addBerth(@RequestBody Berth berth) {
        berthService.insertBerth(berth);
        return responseModel;
    }


    /*病床查询*/
    /*通过科室ID和病床查询*/
    @RequestMapping(value = "/berth/getByID")
    public @ResponseBody
    PageResponseModel queryBerth(@RequestBody BerthInput berthInput) {

        List<BerthVo> list= berthService.selectBerth(berthInput);
        pageResponseModel.setPagination(berthInput.pagination);
        berthInput.pagination.setTotal(berthService.selectBerthTotal(berthInput));
        pageResponseModel.setCode(200);
        pageResponseModel.setMsg("查询成功");
        pageResponseModel.setData(list);
        return  pageResponseModel;
    }


    /*科室查询*/
    /*get方式访问，返回科室id和科室名*/
    @RequestMapping(value = "/department/list")
    public @ResponseBody ResponseModel queryDepartment()
    {
        responseModel.setNull();
        responseModel.setCode(200);
        responseModel.setMsg("查询成功");
        responseModel.setData(departmentService.selectDepartment());
        return  responseModel;
    }


    /*病床删除
    * 传入病床ID号
    * */
    @RequestMapping(value = "/berth/remove")
    public  @ResponseBody ResponseModel deleteBerth(@RequestBody  int berthId)
    {
        berthService.deleteBerthById(berthId);
        return responseModel;
    }

    /*病床床垫绑定解绑*/
    @RequestMapping(value = "/berth/bind")
    public @ResponseBody ResponseModel berthBind(@RequestBody BerthBindInput berthBindInput)
    {
        berthService.berthBind(berthBindInput);
        return responseModel;
    }

}

